//
//  ExchangeIntegrateViewModel.m
//  EnvironmentalProtection
//
//  Created by HCreater on 2019/1/18.
//  Copyright © 2019年 HCreater. All rights reserved.
//

#import "ExchangeIntegrateViewModel.h"

@implementation ExchangeIntegrateViewModel

#pragma mark - Ovrride
- (void)initialize
{
    [super initialize];
    
    @weakify(self)
    
    _nextCmd = [[RACCommand alloc] initWithSignalBlock:^RACSignal *(id input)
                {
                    @strongify(self);
                    
                    return [self _requestExchangeSignal];
                }];
}

- (RACSignal*)_requestExchangeSignal
{
    @weakify(self);
    
    UserManagerV2* um = [UserManagerV2 sharedUserManagerV2];
    NSString* strUserID = um.userData.userID;
    
    return [RACSignal createSignal:^RACDisposable *(id<RACSubscriber> subscriber)
            {
                @strongify(self);
                
                [[AFNetWorkUtils racPOSTWthURL:url_interface_order_integralconvert params:interface_param_order_integralconvert(strUserID, self.coin)] subscribeNext:^(id x)
                 {
                     [subscriber sendNext:x];
                     [subscriber sendCompleted];
                 } error:^(NSError *error)
                 {
                     NSString* strError = [error.userInfo[customErrorInfoKey] isNotBlank] ? error.userInfo[customErrorInfoKey] : @"兑换失败";
                     [subscriber sendError:[NSError errorWithDomain:SUCommandErrorDomain code:SUCommandErrorCode userInfo:@{SUCommandErrorUserInfoKey:strError}]];
                     [subscriber sendCompleted];
                 }];
                
                return nil;
            }];
}

@end
